/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.mapreduce.standard.mappers;

import aiaudio.processing.base.mapreduce.CoordinateDoubleValueKey;
import aiaudio.database.tables.RatingsListTable;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;

/**
 *
 * @author nastya
 */
public class UserToArtistValueRatingTableMapper extends TableMapper<ImmutableBytesWritable, CoordinateDoubleValueKey> {

    @Override
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
        try {
            byte[] artistKey = RatingsListTable.getArtistAsBytes(value);
            byte[] userKey = RatingsListTable.getUserAsBytes(value);
            double listenCount = RatingsListTable.getListenCount(value);

            context.write(new ImmutableBytesWritable(userKey), new CoordinateDoubleValueKey(listenCount, artistKey));
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
    }
}
